package StudyCode.summary.mycollection;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class SumsAnArrayRecursively {
	public static int sumArray(int fromIndex, int toIndex, int[] array) {
		return sumArrayHelper(fromIndex, toIndex, 0, array);
	}

	private static int sumArrayHelper(int start, int end, int sum,
	                                  int[] array) {
		if (start > end) {
			return sum;
		} else {
			sum = sum + array[start]
					+ sumArrayHelper(start + 1, end, sum, array);
			return sum;
		}
	}
}
